﻿using Microsoft.AspNetCore.SignalR;
using PLCS.Domain.Equipments;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Volo.Abp.AspNetCore.SignalR;

namespace PLCS.Application.EquipmentApp.Hubs
{
    public class RGVHub : AbpHub
    {
        private readonly IEquipmentRepository _repository;

        public RGVHub(IEquipmentRepository repository)
        {
            _repository = repository;
        }

        public override Task OnConnectedAsync()
        {
            return base.OnConnectedAsync();
        }

        public async Task InitalStatus(string name)
        {
            await Task.Run(async () =>
            {
                Equipment equipment = await _repository.FindAsync(x => x.EquName == name);
                if (equipment != null)
                {
                    await Clients.Caller.SendAsync("ChangeStatus", name, equipment.Status);
                    await Clients.Caller.SendAsync("ChangeLocation", name, equipment.CurrentStation);
                }
            });
        }
    }
}